{"cells":[{"cell_type":"markdown","metadata":{"id":"_MUPHXTazbdf"},"source":["### Installing necessary libraries"]},{"cell_type":"code","execution_count":2,"metadata":{"colab":{"base_uri":"https://localhost:8080/"},"id":"3caiVpouzbdj","executionInfo":{"status":"ok","timestamp":1688137022334,"user_tz":-330,"elapsed":7048,"user":{"displayName":"Sachi Shah","userId":"15163951659086721462"}},"outputId":"192cd968-5632-4e6d-9ee3-665bb88febdc"},"outputs":[{"output_type":"stream","name":"stdout","text":["Collecting pygwalker\n","  Downloading pygwalker-0.1.11-py3-none-any.whl (616 kB)\n","\u001b[?25l     \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m0.0/616.2 kB\u001b[0m \u001b[31m?\u001b[0m eta \u001b[36m-:--:--\u001b[0m\r\u001b[2K     \u001b[91m━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[90m╺\u001b[0m\u001b[90m━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m286.7/616.2 kB\u001b[0m \u001b[31m8.3 MB/s\u001b[0m eta \u001b[36m0:00:01\u001b[0m\r\u001b[2K     \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m616.2/616.2 kB\u001b[0m \u001b[31m10.5 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n","\u001b[?25hCollecting astor (from pygwalker)\n","  Downloading astor-0.8.1-py2.py3-none-any.whl (27 kB)\n","Requirement already satisfied: ipython in /usr/local/lib/python3.10/dist-packages (from pygwalker) (7.34.0)\n","Requirement already satisfied: jinja2 in /usr/local/lib/python3.10/dist-packages (from pygwalker) (3.1.2)\n","Requirement already satisfied: typing-extensions in /usr/local/lib/python3.10/dist-packages (from pygwalker) (4.6.3)\n","Requirement already satisfied: setuptools>=18.5 in /usr/local/lib/python3.10/dist-packages (from ipython->pygwalker) (67.7.2)\n","Collecting jedi>=0.16 (from ipython->pygwalker)\n","  Downloading jedi-0.18.2-py2.py3-none-any.whl (1.6 MB)\n","\u001b[2K     \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m1.6/1.6 MB\u001b[0m \u001b[31m49.7 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n","\u001b[?25hRequirement already satisfied: decorator in /usr/local/lib/python3.10/dist-packages (from ipython->pygwalker) (4.4.2)\n","Requirement already satisfied: pickleshare in /usr/local/lib/python3.10/dist-packages (from ipython->pygwalker) (0.7.5)\n","Requirement already satisfied: traitlets>=4.2 in /usr/local/lib/python3.10/dist-packages (from ipython->pygwalker) (5.7.1)\n","Requirement already satisfied: prompt-toolkit!=3.0.0,!=3.0.1,<3.1.0,>=2.0.0 in /usr/local/lib/python3.10/dist-packages (from ipython->pygwalker) (3.0.38)\n","Requirement already satisfied: pygments in /usr/local/lib/python3.10/dist-packages (from ipython->pygwalker) (2.14.0)\n","Requirement already satisfied: backcall in /usr/local/lib/python3.10/dist-packages (from ipython->pygwalker) (0.2.0)\n","Requirement already satisfied: matplotlib-inline in /usr/local/lib/python3.10/dist-packages (from ipython->pygwalker) (0.1.6)\n","Requirement already satisfied: pexpect>4.3 in /usr/local/lib/python3.10/dist-packages (from ipython->pygwalker) (4.8.0)\n","Requirement already satisfied: MarkupSafe>=2.0 in /usr/local/lib/python3.10/dist-packages (from jinja2->pygwalker) (2.1.3)\n","Requirement already satisfied: parso<0.9.0,>=0.8.0 in /usr/local/lib/python3.10/dist-packages (from jedi>=0.16->ipython->pygwalker) (0.8.3)\n","Requirement already satisfied: ptyprocess>=0.5 in /usr/local/lib/python3.10/dist-packages (from pexpect>4.3->ipython->pygwalker) (0.7.0)\n","Requirement already satisfied: wcwidth in /usr/local/lib/python3.10/dist-packages (from prompt-toolkit!=3.0.0,!=3.0.1,<3.1.0,>=2.0.0->ipython->pygwalker) (0.2.6)\n","Installing collected packages: jedi, astor, pygwalker\n","Successfully installed astor-0.8.1 jedi-0.18.2 pygwalker-0.1.11\n"]}],"source":["!pip install pygwalker"]},{"cell_type":"markdown","metadata":{"id":"r96ZM4akzbdk"},"source":["### Importing libraries"]},{"cell_type":"code","execution_count":5,"metadata":{"id":"14ELR0OUzbdk","executionInfo":{"status":"ok","timestamp":1688137052253,"user_tz":-330,"elapsed":8,"user":{"displayName":"Sachi Shah","userId":"15163951659086721462"}}},"outputs":[],"source":["import pygwalker as pyg\n","import pandas as pd\n","from google.colab import files\n","import io"]},{"cell_type":"markdown","metadata":{"id":"tycHrmggzbdk"},"source":["### Reading the sample .csv file to be visualized"]},{"cell_type":"code","execution_count":11,"metadata":{"colab":{"base_uri":"https://localhost:8080/","height":323},"id":"NHdbP1F3zbdk","executionInfo":{"status":"ok","timestamp":1688137449895,"user_tz":-330,"elapsed":16196,"user":{"displayName":"Sachi Shah","userId":"15163951659086721462"}},"outputId":"3633a4c0-d2b4-4a00-8260-a1d7754836f6"},"outputs":[{"output_type":"display_data","data":{"text/plain":["<IPython.core.display.HTML object>"],"text/html":["\n","     <input type=\"file\" id=\"files-65bdc65c-793e-4fe6-8934-9f7738e8bbd8\" name=\"files[]\" multiple disabled\n","        style=\"border:none\" />\n","     <output id=\"result-65bdc65c-793e-4fe6-8934-9f7738e8bbd8\">\n","      Upload widget is only available when the cell has been executed in the\n","      current browser session. Please rerun this cell to enable.\n","      </output>\n","      <script>// Copyright 2017 Google LLC\n","//\n","// Licensed under the Apache License, Version 2.0 (the \"License\");\n","// you may not use this file except in compliance with the License.\n","// You may obtain a copy of the License at\n","//\n","//      http://www.apache.org/licenses/LICENSE-2.0\n","//\n","// Unless required by applicable law or agreed to in writing, software\n","// distributed under the License is distributed on an \"AS IS\" BASIS,\n","// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n","// See the License for the specific language governing permissions and\n","// limitations under the License.\n","\n","/**\n"," * @fileoverview Helpers for google.colab Python module.\n"," */\n","(function(scope) {\n","function span(text, styleAttributes = {}) {\n","  const element = document.createElement('span');\n","  element.textContent = text;\n","  for (const key of Object.keys(styleAttributes)) {\n","    element.style[key] = styleAttributes[key];\n","  }\n","  return element;\n","}\n","\n","// Max number of bytes which will be uploaded at a time.\n","const MAX_PAYLOAD_SIZE = 100 * 1024;\n","\n","function _uploadFiles(inputId, outputId) {\n","  const steps = uploadFilesStep(inputId, outputId);\n","  const outputElement = document.getElementById(outputId);\n","  // Cache steps on the outputElement to make it available for the next call\n","  // to uploadFilesContinue from Python.\n","  outputElement.steps = steps;\n","\n","  return _uploadFilesContinue(outputId);\n","}\n","\n","// This is roughly an async generator (not supported in the browser yet),\n","// where there are multiple asynchronous steps and the Python side is going\n","// to poll for completion of each step.\n","// This uses a Promise to block the python side on completion of each step,\n","// then passes the result of the previous step as the input to the next step.\n","function _uploadFilesContinue(outputId) {\n","  const outputElement = document.getElementById(outputId);\n","  const steps = outputElement.steps;\n","\n","  const next = steps.next(outputElement.lastPromiseValue);\n","  return Promise.resolve(next.value.promise).then((value) => {\n","    // Cache the last promise value to make it available to the next\n","    // step of the generator.\n","    outputElement.lastPromiseValue = value;\n","    return next.value.response;\n","  });\n","}\n","\n","/**\n"," * Generator function which is called between each async step of the upload\n"," * process.\n"," * @param {string} inputId Element ID of the input file picker element.\n"," * @param {string} outputId Element ID of the output display.\n"," * @return {!Iterable<!Object>} Iterable of next steps.\n"," */\n","function* uploadFilesStep(inputId, outputId) {\n","  const inputElement = document.getElementById(inputId);\n","  inputElement.disabled = false;\n","\n","  const outputElement = document.getElementById(outputId);\n","  outputElement.innerHTML = '';\n","\n","  const pickedPromise = new Promise((resolve) => {\n","    inputElement.addEventListener('change', (e) => {\n","      resolve(e.target.files);\n","    });\n","  });\n","\n","  const cancel = document.createElement('button');\n","  inputElement.parentElement.appendChild(cancel);\n","  cancel.textContent = 'Cancel upload';\n","  const cancelPromise = new Promise((resolve) => {\n","    cancel.onclick = () => {\n","      resolve(null);\n","    };\n","  });\n","\n","  // Wait for the user to pick the files.\n","  const files = yield {\n","    promise: Promise.race([pickedPromise, cancelPromise]),\n","    response: {\n","      action: 'starting',\n","    }\n","  };\n","\n","  cancel.remove();\n","\n","  // Disable the input element since further picks are not allowed.\n","  inputElement.disabled = true;\n","\n","  if (!files) {\n","    return {\n","      response: {\n","        action: 'complete',\n","      }\n","    };\n","  }\n","\n","  for (const file of files) {\n","    const li = document.createElement('li');\n","    li.append(span(file.name, {fontWeight: 'bold'}));\n","    li.append(span(\n","        `(${file.type || 'n/a'}) - ${file.size} bytes, ` +\n","        `last modified: ${\n","            file.lastModifiedDate ? file.lastModifiedDate.toLocaleDateString() :\n","                                    'n/a'} - `));\n","    const percent = span('0% done');\n","    li.appendChild(percent);\n","\n","    outputElement.appendChild(li);\n","\n","    const fileDataPromise = new Promise((resolve) => {\n","      const reader = new FileReader();\n","      reader.onload = (e) => {\n","        resolve(e.target.result);\n","      };\n","      reader.readAsArrayBuffer(file);\n","    });\n","    // Wait for the data to be ready.\n","    let fileData = yield {\n","      promise: fileDataPromise,\n","      response: {\n","        action: 'continue',\n","      }\n","    };\n","\n","    // Use a chunked sending to avoid message size limits. See b/62115660.\n","    let position = 0;\n","    do {\n","      const length = Math.min(fileData.byteLength - position, MAX_PAYLOAD_SIZE);\n","      const chunk = new Uint8Array(fileData, position, length);\n","      position += length;\n","\n","      const base64 = btoa(String.fromCharCode.apply(null, chunk));\n","      yield {\n","        response: {\n","          action: 'append',\n","          file: file.name,\n","          data: base64,\n","        },\n","      };\n","\n","      let percentDone = fileData.byteLength === 0 ?\n","          100 :\n","          Math.round((position / fileData.byteLength) * 100);\n","      percent.textContent = `${percentDone}% done`;\n","\n","    } while (position < fileData.byteLength);\n","  }\n","\n","  // All done.\n","  yield {\n","    response: {\n","      action: 'complete',\n","    }\n","  };\n","}\n","\n","scope.google = scope.google || {};\n","scope.google.colab = scope.google.colab || {};\n","scope.google.colab._files = {\n","  _uploadFiles,\n","  _uploadFilesContinue,\n","};\n","})(self);\n","</script> "]},"metadata":{}},{"output_type":"stream","name":"stdout","text":["Saving sample_salaries.csv to sample_salaries.csv\n"]},{"output_type":"execute_result","data":{"text/plain":["   work_year experience_level employment_type                 job_title  \\\n","0       2023               SE              FT  Principal Data Scientist   \n","1       2023               MI              CT               ML Engineer   \n","2       2023               MI              CT               ML Engineer   \n","3       2023               SE              FT            Data Scientist   \n","4       2023               SE              FT            Data Scientist   \n","\n","   salary salary_currency  salary_in_usd employee_residence  remote_ratio  \\\n","0   80000             EUR          85847                 ES           100   \n","1   30000             USD          30000                 US           100   \n","2   25500             USD          25500                 US           100   \n","3  175000             USD         175000                 CA           100   \n","4  120000             USD         120000                 CA           100   \n","\n","  company_location company_size  \n","0               ES            L  \n","1               US            S  \n","2               US            S  \n","3               CA            M  \n","4               CA            M  "],"text/html":["\n","  <div id=\"df-b22f10e4-2886-4ee7-bf32-afb8036f6c40\">\n","    <div class=\"colab-df-container\">\n","      <div>\n","<style scoped>\n","    .dataframe tbody tr th:only-of-type {\n","        vertical-align: middle;\n","    }\n","\n","    .dataframe tbody tr th {\n","        vertical-align: top;\n","    }\n","\n","    .dataframe thead th {\n","        text-align: right;\n","    }\n","</style>\n","<table border=\"1\" class=\"dataframe\">\n","  <thead>\n","    <tr style=\"text-align: right;\">\n","      <th></th>\n","      <th>work_year</th>\n","      <th>experience_level</th>\n","      <th>employment_type</th>\n","      <th>job_title</th>\n","      <th>salary</th>\n","      <th>salary_currency</th>\n","      <th>salary_in_usd</th>\n","      <th>employee_residence</th>\n","      <th>remote_ratio</th>\n","      <th>company_location</th>\n","      <th>company_size</th>\n","    </tr>\n","  </thead>\n","  <tbody>\n","    <tr>\n","      <th>0</th>\n","      <td>2023</td>\n","      <td>SE</td>\n","      <td>FT</td>\n","      <td>Principal Data Scientist</td>\n","      <td>80000</td>\n","      <td>EUR</td>\n","      <td>85847</td>\n","      <td>ES</td>\n","      <td>100</td>\n","      <td>ES</td>\n","      <td>L</td>\n","    </tr>\n","    <tr>\n","      <th>1</th>\n","      <td>2023</td>\n","      <td>MI</td>\n","      <td>CT</td>\n","      <td>ML Engineer</td>\n","      <td>30000</td>\n","      <td>USD</td>\n","      <td>30000</td>\n","      <td>US</td>\n","      <td>100</td>\n","      <td>US</td>\n","      <td>S</td>\n","    </tr>\n","    <tr>\n","      <th>2</th>\n","      <td>2023</td>\n","      <td>MI</td>\n","      <td>CT</td>\n","      <td>ML Engineer</td>\n","      <td>25500</td>\n","      <td>USD</td>\n","      <td>25500</td>\n","      <td>US</td>\n","      <td>100</td>\n","      <td>US</td>\n","      <td>S</td>\n","    </tr>\n","    <tr>\n","      <th>3</th>\n","      <td>2023</td>\n","      <td>SE</td>\n","      <td>FT</td>\n","      <td>Data Scientist</td>\n","      <td>175000</td>\n","      <td>USD</td>\n","      <td>175000</td>\n","      <td>CA</td>\n","      <td>100</td>\n","      <td>CA</td>\n","      <td>M</td>\n","    </tr>\n","    <tr>\n","      <th>4</th>\n","      <td>2023</td>\n","      <td>SE</td>\n","      <td>FT</td>\n","      <td>Data Scientist</td>\n","      <td>120000</td>\n","      <td>USD</td>\n","      <td>120000</td>\n","      <td>CA</td>\n","      <td>100</td>\n","      <td>CA</td>\n","      <td>M</td>\n","    </tr>\n","  </tbody>\n","</table>\n","</div>\n","      <button class=\"colab-df-convert\" onclick=\"convertToInteractive('df-b22f10e4-2886-4ee7-bf32-afb8036f6c40')\"\n","              title=\"Convert this dataframe to an interactive table.\"\n","              style=\"display:none;\">\n","        \n","  <svg xmlns=\"http://www.w3.org/2000/svg\" height=\"24px\"viewBox=\"0 0 24 24\"\n","       width=\"24px\">\n","    <path d=\"M0 0h24v24H0V0z\" fill=\"none\"/>\n","    <path d=\"M18.56 5.44l.94 2.06.94-2.06 2.06-.94-2.06-.94-.94-2.06-.94 2.06-2.06.94zm-11 1L8.5 8.5l.94-2.06 2.06-.94-2.06-.94L8.5 2.5l-.94 2.06-2.06.94zm10 10l.94 2.06.94-2.06 2.06-.94-2.06-.94-.94-2.06-.94 2.06-2.06.94z\"/><path d=\"M17.41 7.96l-1.37-1.37c-.4-.4-.92-.59-1.43-.59-.52 0-1.04.2-1.43.59L10.3 9.45l-7.72 7.72c-.78.78-.78 2.05 0 2.83L4 21.41c.39.39.9.59 1.41.59.51 0 1.02-.2 1.41-.59l7.78-7.78 2.81-2.81c.8-.78.8-2.07 0-2.86zM5.41 20L4 18.59l7.72-7.72 1.47 1.35L5.41 20z\"/>\n","  </svg>\n","      </button>\n","      \n","  <style>\n","    .colab-df-container {\n","      display:flex;\n","      flex-wrap:wrap;\n","      gap: 12px;\n","    }\n","\n","    .colab-df-convert {\n","      background-color: #E8F0FE;\n","      border: none;\n","      border-radius: 50%;\n","      cursor: pointer;\n","      display: none;\n","      fill: #1967D2;\n","      height: 32px;\n","      padding: 0 0 0 0;\n","      width: 32px;\n","    }\n","\n","    .colab-df-convert:hover {\n","      background-color: #E2EBFA;\n","      box-shadow: 0px 1px 2px rgba(60, 64, 67, 0.3), 0px 1px 3px 1px rgba(60, 64, 67, 0.15);\n","      fill: #174EA6;\n","    }\n","\n","    [theme=dark] .colab-df-convert {\n","      background-color: #3B4455;\n","      fill: #D2E3FC;\n","    }\n","\n","    [theme=dark] .colab-df-convert:hover {\n","      background-color: #434B5C;\n","      box-shadow: 0px 1px 3px 1px rgba(0, 0, 0, 0.15);\n","      filter: drop-shadow(0px 1px 2px rgba(0, 0, 0, 0.3));\n","      fill: #FFFFFF;\n","    }\n","  </style>\n","\n","      <script>\n","        const buttonEl =\n","          document.querySelector('#df-b22f10e4-2886-4ee7-bf32-afb8036f6c40 button.colab-df-convert');\n","        buttonEl.style.display =\n","          google.colab.kernel.accessAllowed ? 'block' : 'none';\n","\n","        async function convertToInteractive(key) {\n","          const element = document.querySelector('#df-b22f10e4-2886-4ee7-bf32-afb8036f6c40');\n","          const dataTable =\n","            await google.colab.kernel.invokeFunction('convertToInteractive',\n","                                                     [key], {});\n","          if (!dataTable) return;\n","\n","          const docLinkHtml = 'Like what you see? Visit the ' +\n","            '<a target=\"_blank\" href=https://colab.research.google.com/notebooks/data_table.ipynb>data table notebook</a>'\n","            + ' to learn more about interactive tables.';\n","          element.innerHTML = '';\n","          dataTable['output_type'] = 'display_data';\n","          await google.colab.output.renderOutput(dataTable, element);\n","          const docLink = document.createElement('div');\n","          docLink.innerHTML = docLinkHtml;\n","          element.appendChild(docLink);\n","        }\n","      </script>\n","    </div>\n","  </div>\n","  "]},"metadata":{},"execution_count":11}],"source":["uploaded = files.upload()\n","df = pd.read_csv(io.BytesIO(uploaded['sample_salaries.csv']))\n","df.head()"]},{"cell_type":"code","execution_count":12,"metadata":{"colab":{"base_uri":"https://localhost:8080/","height":887,"output_embedded_package_id":"1-QnSFOlE6usCvDF2AiWdz7amNkTkedyb"},"id":"MJE0H92Ezbdl","executionInfo":{"status":"ok","timestamp":1688137457172,"user_tz":-330,"elapsed":2760,"user":{"displayName":"Sachi Shah","userId":"15163951659086721462"}},"outputId":"b2a03dc8-b78a-4fc6-d195-f6613bd35d04"},"outputs":[{"output_type":"display_data","data":{"text/plain":"Output hidden; open in https://colab.research.google.com to view."},"metadata":{}}],"source":["gwalker = pyg.walk(df)"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"R7jEJEW3zbdl"},"outputs":[],"source":[]},{"cell_type":"markdown","source":["**Export the graph visualized as .png or .svg**"],"metadata":{"id":"WRwa3T3x4Wf1"}},{"cell_type":"markdown","source":["![image.png]()"],"metadata":{"id":"XYRQvfMa3_3m"}},{"cell_type":"code","source":[],"metadata":{"id":"y_2TjrYY4Adx"},"execution_count":null,"outputs":[]}],"metadata":{"kernelspec":{"display_name":"Python 3","language":"python","name":"python3"},"language_info":{"codemirror_mode":{"name":"ipython","version":3},"file_extension":".py","mimetype":"text/x-python","name":"python","nbconvert_exporter":"python","pygments_lexer":"ipython3","version":"3.8.5"},"colab":{"provenance":[]}},"nbformat":4,"nbformat_minor":0}